package com.check.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.check.dao.PcwhDao;
import com.check.pojo.PageObject;
import com.check.pojo.Pcwh;
import com.check.service.PcwhService;

@Service("pcwhService")
public class PcwhServiceImpl implements PcwhService{

	@Autowired
	@Qualifier("pcwhDao")
	private PcwhDao pcwhDao;
	
	public List<Pcwh> findAllPcwh(PageObject pageObject) {
		Map<Object,Object> map=new HashMap<Object, Object>();
		map.put("startNum", pageObject.getStartNum());
		map.put("endNum", pageObject.getEndNum());
		return pcwhDao.findAllPcwh(map);
	}

	public int findPcwhCount() {
		return pcwhDao.findPcwhCount();
	}

	public boolean insertPcwh(Pcwh pcwh) {
		boolean flag=false;
		try {
			pcwhDao.insertPcwh(pcwh);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public Pcwh findByCheckYear(String checkYear) {
		Pcwh pcwh=null;
		try {
			pcwh=pcwhDao.findByCheckYear(checkYear);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pcwh;
	}

	public boolean updatePcwh(Pcwh pcwh) {
		boolean flag=false;
		try {
			pcwhDao.updatePcwh(pcwh);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public boolean deletePcwh(String checkYear) {
		boolean flag=false;
		try {
			pcwhDao.deletePcwh(checkYear);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public boolean updateActivePcwh(String checkYear) {
		boolean flag=false;
		try {
			pcwhDao.activePcwh(checkYear);
			pcwhDao.unactivePcwhElse(checkYear);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public boolean updateUnactivePcwh(String checkYear) {
		boolean flag=false;
		try {
			pcwhDao.unactivePcwh(checkYear);
			flag=true;
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			flag=false;
		}
		return flag;
	}

	public Pcwh findActivePcwh(){
		Pcwh pcwh=null;
		try {
			pcwh=pcwhDao.findActivePcwh();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return pcwh;
	}

	public List<Pcwh> findAllPcwh() {
		return pcwhDao.findAllPcwh(new HashMap());
	}
}
